<?php

use yii\helpers\Url;
$this->inline("title","添加分类");
$request = Yii::$app->request->post();
?>
<div class="panel">
    <div class="panel-body">
        <div class="row">
            <div class="col-lg-6">
                <div class="card-box">
                    <h4 class="m-t-0 header-title"><b>分类创建</b></h4>

                    <form class="form-horizontal" action="" method="post" data-parsley-validate novalidate>
                        <input type="hidden" name="<?=Yii::$app->request->csrfParam?>" value="<?=Yii::$app->request->csrfToken?>">
                        <?php if (isset($model)):?>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">上级分类：</label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control" value="<?=isset($model['cname']) ?$model['cname']:''?>" readonly name="pname">
                                <input type="hidden" name="pid" value="<?=isset($model['id']) ?$model['id']:''?>">
                            </div>
                        </div>
                        <?php endif;?>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">分类名称：</label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control" value="<?=isset($request['cname']) ?$request['cname']:''?>" name="cname" placeholder="" parsley-trigger="change" required autofocus>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="email" class="col-sm-3 control-label">分类描述：</label>
                            <div class="col-sm-8">
                                <textarea class="form-control" name="desc" parsley-trigger="change" required><?=isset($request['desc']) ?$request['desc']:''?></textarea>
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-sm-offset-3 col-sm-9">
                                <button type="submit" class="btn btn-primary waves-effect waves-light">
                                    保存信息
                                </button>
                                <button type="button" onclick="location.href='<?=Url::toRoute('/category')?>'" class="btn btn-default waves-effect waves-light m-l-5">
                                    返回列表
                                </button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<?php $this->beginBlock("jsText","append")?>
    <script type="text/javascript">
        $(document).ready(function() {
            $('form').parsley();
        });
    </script>
<?php $this->endBlock();?>